<html>
<head><meta charset="utf-8"><title>Repl support for associated types · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Repl.20support.20for.20associated.20types.html">Repl support for associated types</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="186456740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Repl%20support%20for%20associated%20types/near/186456740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sydney Acksman <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Repl.20support.20for.20associated.20types.html#186456740">(Jan 24 2020 at 02:06)</a>:</h4>
<p>I have a trait impl that's unique but can't be solved by the current Rust compiler for reasons. I'm currently trying to write it as a program to load into the repl to see if chalk can solve it but I can't get it to understand associated types. What exactly is the syntax for associated types in the repl?</p>



<a name="186457294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Repl%20support%20for%20associated%20types/near/186457294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sydney Acksman <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Repl.20support.20for.20associated.20types.html#186457294">(Jan 24 2020 at 02:20)</a>:</h4>
<p>It requires full specified type syntax aka <code>&lt;T as X&gt;::Y</code> doesn't it.</p>



<a name="186457558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Repl%20support%20for%20associated%20types/near/186457558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Repl.20support.20for.20associated.20types.html#186457558">(Jan 24 2020 at 02:27)</a>:</h4>
<p>To use an associated type, yes you need <code>&lt;T as X&gt;::Y</code></p>



<a name="186457568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Repl%20support%20for%20associated%20types/near/186457568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Repl.20support.20for.20associated.20types.html#186457568">(Jan 24 2020 at 02:27)</a>:</h4>
<p>I'm actually surprised there isn't an example of associated types in the <code>libstd.chalk</code></p>



<a name="186457646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Repl%20support%20for%20associated%20types/near/186457646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sydney Acksman <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Repl.20support.20for.20associated.20types.html#186457646">(Jan 24 2020 at 02:29)</a>:</h4>
<p>Alright, new question: why doesn't this solve.</p>
<div class="codehilite"><pre><span></span>trait Sized { }

trait ValueType {
    type Inner;
}
trait Value&lt;V&gt; where V: ValueType&lt;Inner = Self&gt; { }
trait Packable where Self: ValueType { }
struct Packed&lt;V&gt; where V: Packable { }
impl&lt;V&gt; ValueType for Packed&lt;V&gt; where V: Packable {
    type Inner = &lt;V as ValueType&gt;::Inner;
}

struct i32 { }
struct Int32 { }
impl ValueType for Int32 {
    type Inner = i32;
}
impl Packable for Int32 { }
impl Value&lt;Int32&gt; for i32 { }

struct Vec&lt;T&gt; where T: Sized { }
trait RepeatedField&lt;V&gt; { }
impl&lt;V&gt; RepeatedField&lt;V&gt; for Vec&lt;&lt;V as ValueType&gt;::Inner&gt; where V: ValueType, &lt;V as ValueType&gt;::Inner: Value&lt;V&gt; { }
impl&lt;V&gt; RepeatedField&lt;Packed&lt;V&gt;&gt; for Vec&lt;&lt;Packed&lt;V&gt; as ValueType&gt;::Inner&gt; where V: Packable, &lt;V as ValueType&gt;::Inner: Value&lt;V&gt; { }
</pre></div>


<p>Chalk says there's an overlapping impl, but I can't see it. The impl over Packed should be different from <code>V: ValueType, V::Inner: Value&lt;V&gt;</code> since <code>Packed&lt;V&gt;::Inner</code> doesn't implement <code>Value&lt;Packed&lt;V&gt;&gt;</code>. So it should be unique, right?</p>



<a name="186457719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Repl%20support%20for%20associated%20types/near/186457719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sydney Acksman <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Repl.20support.20for.20associated.20types.html#186457719">(Jan 24 2020 at 02:30)</a>:</h4>
<p>Damn, after explaining it now I see it.</p>



<a name="186460181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Repl%20support%20for%20associated%20types/near/186460181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sydney Acksman <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Repl.20support.20for.20associated.20types.html#186460181">(Jan 24 2020 at 03:34)</a>:</h4>
<p>I have figured out a fix though that falls inline with my original logic for why this was valid earlier</p>
<div class="codehilite"><pre><span></span>struct Packed&lt;V&gt; where V: Packable, &lt;V as ValueType&gt;::Inner: Value&lt;V&gt; { }
impl&lt;V&gt; ValueType for Packed&lt;V&gt; where V: Packable, &lt;V as ValueType&gt;::Inner: Value&lt;V&gt; {
    type Inner = &lt;V as ValueType&gt;::Inner;
}
</pre></div>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>